package com.douziit.meilianoa.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.douziit.meilianoa.base.annotation.NoCheckToken;
import com.douziit.meilianoa.base.request.PageRequest;
import com.douziit.meilianoa.base.response.ResponseData;
import com.douziit.meilianoa.base.response.ResponseUtil;
import com.douziit.meilianoa.entity.Invoice;
import com.douziit.meilianoa.service.InvoiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * 开票信息控制类
 */
@RestController
@RequestMapping("/invoice")
public class InvoiceController {

    @Autowired
    private InvoiceService invoiceService;

    /**
     * 添加开票信息
     */
    @PostMapping("/addInvoices")
    @Transactional(rollbackFor = Exception.class)
    public ResponseData addInvoice(@RequestBody List<Invoice> invoices){

        if (invoices != null && invoices.size()!=0){
            for (Invoice invoice : invoices){
                invoiceService.save(invoice);
            }
        }
        return ResponseUtil.jsonSuccess(0);
    }

    /**
     * 修改开票信息
     */
    @PostMapping("/changeInvoice")
    public ResponseData changeInvoice(@RequestBody Invoice invoice){

        invoiceService.updateById(invoice);
        return ResponseUtil.jsonSuccess(0);
    }

    /**
     * 开票信息列表详情
     */
    @PostMapping("/listInvoice")
    public ResponseData listInvoice(@RequestBody PageRequest req){

        List<Invoice> invoices = invoiceService.list(new QueryWrapper<Invoice>().eq("project_id",req.getProjectId()));
        return ResponseUtil.jsonSuccess(invoices);
    }

}
